package com.example.dao;

import com.example.entity.AdminInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface AdminInfoDao extends Mapper<AdminInfo> {

    @Select("select * from admin_info where name=#{name} and password =#{password}")
    AdminInfo findByNameAndPassword(@Param("name") String name,@Param("password") String password);

    @Select("select * from admin_info where id=#{id} ")
    AdminInfo findById(@Param("id") long id);

    @Update("UPDATE admin_info " +
            "SET name = #{name}, sex = #{sex}, age = #{age}, phone = #{phone}, password = #{password} " +
            "WHERE id = #{id} ")
    void updateById(@Param("id") long id,
                    @Param("name") String name,
                    @Param("password") String password,
                    @Param("sex") String sex,
                    @Param("age") String age,
                    @Param("phone") String phone,
                    @Param("level") Integer level);

    @Select("select * from admin_info where name=#{name} ")
    AdminInfo findByName(@Param("name") String name);

    @Select("select * from admin_info")
    List<AdminInfo> selectAllAdmin();
    @Delete("DELETE FROM admin_info WHERE id = #{id}")
    void deleteById(@Param("id") Long id);

    @Select("select * from admin_info where name like concat('%',#{name},'%')")
    List<AdminInfo> findByNamePage(@Param("name")String name);
}
